const express=require('express');
const mysql=require('mysql');
const common=require('../../libs/common.js');
const urlobj=require('url');
const multer=require('multer');
const multerObj=multer({dest:'../../www/upload'});
const pathLib=require('path');
const fs=require('fs');
//链接数据库
var db=mysql.createPool({
    host:'localhost',
    user:'root',
    password:'',
    database:'leasedb'
});
module.exports = function() {
    var router = express.Router();

	//根据帖子id查询帖子信息
	router.use('/ForumDetalis', function(req, res){
		db.query("SELECT * FROM forumbinfo,userInfo WHERE userInfo.userId=forumbinfo.userId and forumbInfo.forumBId="+req.body.forumBId+"",function(err,data){
			if(err)
			{
				res.send('{"status":"400"}').end();
			}
			else
			{
				res.send('{"status":"200","msg":'+JSON.stringify(data)+'}').end();
			}
		});
	});
	//根据帖子id查询该帖子的所有评论
	router.use('/ForumDetalis', function(req, res){
		db.query("SELECT * FROM forumcomment,userInfo WHERE userInfo.userId=forumcomment.userId and forumcomment.forumBId="+req.body.forumBId+"",function(err,data){
			if(err)
			{
				res.send('{"status":"400"}').end();
			}
			else
			{
				res.send('{"status":"200","msg":'+JSON.stringify(data)+'}').end();
			}
		});
	});
    return router;
}